<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
	String path = request.getContextPath();
%>
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
  <meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="icon" href="<%=path%>/images/favicon.ico" type="image/ico">
<meta name="author" content="guowenjie">
<link href="<%=path%>/css/bootstrap.min.css" rel="stylesheet">
<link href="<%=path%>/css/materialdesignicons.min.css" rel="stylesheet">
<link href="<%=path%>/css/style.min.css" rel="stylesheet">
<link rel="stylesheet" href="<%=path%>/js/ion-rangeslider/ion.rangeSlider.min.css">
<link href="<%=path%>/js/jconfirm/jquery-confirm.min.css" rel="stylesheet">
<link href="<%=path%>/js/bootstrap-datepicker/bootstrap-datepicker3.min.css" rel="stylesheet">
<link href="<%=path%>/js/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
<link href="<%=path%>/css/materialdesignicons.min.css" rel="stylesheet">
<link rel="stylesheet" href="<%=path%>/style/layui/css/layui.css">

<script type="text/javascript" src="<%=path%>/js/jquery.min.js"></script>
 <script type="text/javascript" src="<%=path%>/js/main.min.js"></script>
<script src="<%=path%>/js/bootstrap-datepicker/bootstrap-datepicker.min.js"></script>
<script src="<%=path%>/js/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js"></script>
<script type="text/javascript" src="<%=path%>/js/bootstrap.min.js"></script>
<script type="text/javascript" src="<%=path%>/js/bootstrap-table/bootstrap-table.js"></script>
<script type="text/javascript" src="<%=path%>/js/bootstrap-table/bootstrap-table-zh-CN.min.js"></script>
<script type="text/javascript" src="<%=path%>/js/jconfirm/jquery-confirm.min.js"></script>
<script type="text/javascript" src="<%=path%>/style/layui/layui.js"></script>

</head>
 <div class="container-fluid p-t-15">
    
        <div  class="card">
      <div class="card-body">
        <div class="row">
         
         <div id="toolbar" class="toolbar-btn-action">
           <button name="scan" type="button" class="btn btn-primary" id="test5"><span class="mdi mdi-file-pdf" aria-hidden="true"></span>上传</button>       
           <button id="btn_delete" type="button" class="btn btn-danger"  onclick="del()">
              <span class="mdi mdi-window-close" aria-hidden="true"></span>删除
            </button> </div>
        
          <div class="col-md-12">
           <table id="table" ></table>
        </div>
          
          <div style="display:none">
          <input type="text"  id="type"></input>
           <input type="text"  id="wjname"></input>
        
          <input type="text"  id="wjcode"></input>
         </div>
            
        </div>
        
      </div></div></div>
      
       <script type="text/javascript">
       layui.config({
   	    base: '<%=path%>/style/layui/ext/',    
   }).extend({                         // 模块别名
   		loading: 'loading'
   })
       layui.use(['upload','excel'], function(){
	     	    var $ = layui.jquery
	     	   ,excel = layui.excel
	     	    ,upload = layui.upload;
	     	
	     	    
	     	    
	     	   function disabledtzan(){
	          	  
	        	   var scan=document.getElementsByName("scan");
	        	   for(var a=0;a<scan.length;a++){
	        		   let scanbutton = scan[a];
	        		   scanbutton.disabled = true;
	        		 }
	        	   
	            }   
	     	    
	     	  function jctzan(){
	          	  
	        	   var scan=document.getElementsByName("scan");
	        	   for(var a=0;a<scan.length;a++){
	        		   let scanbutton = scan[a];
	        		   scanbutton.disabled = false;
	        		 }
	        	   
	            } 
	     	    
	     	    
	     	    
	     	    
	     	   
	     	  
	     	  //指定允许上传的文件类型
	     	var uppdf =   upload.render({
	     	     elem: '#test5'
	     	     ,url: '<%=path%>/bg/scfgwj'
	     	      ,accept: 'file' //普通文件
	     	       ,acceptMime:'pdf' 
	     	      ,exts:'pdf'
	     	    	 ,auto: false //选择文件后不自动上传
	     	    	 ,data:{
	 	     	    	wjname:function(){
	 	     	    	    
	 	     	    	    return $('#wjname').val();
	 	     	    	  }
	     	     }
	     	     ,field:'file'
	     	    	,before: function(obj){ //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
	     	    	    layer.load(1); //上传loading
	     	    	    disabledtzan();
	     	    	   
	     	    	  }
	     	        ,choose: function(obj) {// 选择文件回调
	     	        	obj.preview(function(index, file, result){
		     	    		  $('#wjname').val(file.name);
		     	    		 uppdf.upload(); 
		     	    	  }); 
	    	          }
	     	    	  ,done: function(res, index, upload){
	     	    		 layer.closeAll('loading'); //关闭loading
		     	    	    jctzan();
	     	    		 if(res.msg=="ok"){
	     	    			search();
	     	    		 }else{
	     	    			$.alert("上传失败"); 	 
	     	    			 
	     	    		 }
	     	    		
	     	    		
	     	    	  }
	     	    	  ,error: function(index, upload){
	     	    	   
	     	    	  }
	     	     
	     	   });
	     	  });
      
       
 
       
       $('#table').bootstrapTable({
    	   classes: 'table table-condensed table-hover',
    		data:[],
    		toolbar: '#toolbar',       // 工具按钮容器	
    	    dataType : 'json',        // 因为本示例中是跨域的调用,所以涉及到ajax都采用jsonp,
    	    pagination: true,                    // 是否显示分页
    	    pageNumber: 1,                       // 初始化加载第一页，默认第一页
    	    pageSize: 10,                        // 每页的记录行数
    	    sidePagination: "client",            // 分页方式：client客户端分页，server服务端分页
    	    columns: [{
  		         checkbox: true    // 是否显示复选框
  		     },{
    	        field: 'fgid',
    	        title: '法规序号',
    	        width:80
    	        
    	    },{
    	        field: 'fgmc',
    	        title: '法规名称',
    	       formatter: function (value, row, index) {
    	        	 var result;
    	        	 result ='<i class="mdi mdi-file-pdf"><a onclick="showpdf(\''+row.wjlj+'\')">'+value+'</a></i>';
    	        	 return result;
    	        }
    	    }],
    	 
    	    onLoadSuccess: function(data){
    	        $("[data-toggle='tooltip']").tooltip();
    	    }
    	});

    	search();
    	function search(){
    	$.ajax({
    		 type: "post",//方法类型
    	   dataType: "json",//预期服务器返回的数据类型 jsonp跨域
    		url: "<%=path%>/bg/getfgdata",
    		data:{
    			"fgmc":$("#gjz").val()
    		}, 
    		success: function(req) {	
    			let data = req.data;
    			$("#table").bootstrapTable('refreshOptions',{data:data});	 
    		},error: function(e){ 
    			console.log(e);
    			
    		}
    	});
    	}




    	function showpdf(filename){
    		
    		 
    	    $.ajax({
    			 type: "post",//方法类型
    		    dataType: "json",//预期服务器返回的数据类型 jsonp跨域
    			url: "<%=path%>/bg/findwj",
    			 data:{
    				"filename":filename
    			}, 
    			success: function(req) {	
    				if(req.msg=="1"){
    					var url = "<%=path%>/bg/pdfwj";
    					 window.open(url);
    				}else{
    					
    					$.alert({
    				        title: '提示',
    				        content: '文件还未上传',
    						buttons: {
    							confirm: {
    								text: '确认',
    								btnClass: 'btn-primary',
    								action: function(){
    				                   
    								}
    							}
    						}
    				    });
    				}
    				 
    			},error: function(){ 
    				
    				
    			}
    		});
      
    	}
      
    	
    	function del(){
     	   let row=$("#table").bootstrapTable('getSelections');     
     	   if(row.length==0){
     		   $.alert({
     	        title: '提示',
     	        content: "请选择要操作的数据"})
        	    }else{
        	    	let fgids = new Array();
         		for(var a=0;a<row.length;a++){
         			
         			fgids.push(row[a].fgid);	
         		}
         		
         		$.ajax({
   	   			 type: "post",//方法类型
   	   		    dataType: "json",//预期服务器返回的数据类型 jsonp跨域
   	   			url: "<%=path%>/bg/delfgwj",
   	   			data:{
   	   				"fgids":fgids.join(",")
   	   			}, 
   	   			success: function(req) {
   	   		    $.alert({
             	        title: '提示',
             	        content: '操作成功',
             			buttons: {
             				confirm: {
             					text: '确认',
             					btnClass: 'btn-primary',
             					action: function(){
             						search();
             					}
             				}
             			}
             	    });
    	   				 
   	   			},error: function(e){ 
   	   			 console.log(e.responseText);	
   	   			}
   	   		});
         		
        	    }
        }
       
      </script>
       </body>

</html>   